home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE20 / EX9.C < prev   
C/C++ Source or Header  |  1995-03-22  |  5KB  |  105 lines

  1. #include <genstub.c>
  2.  
  3. #define EDIT_ID       1000   // Identifies the child window.
  4.  
  5. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  6. {
  7.    switch (uMsg) {
  8.          case WM_CREATE:        // Create ab edit child window to show section keys.
  9.             {
  10.                RECT    rectClient;
  11.                HWND    hWndEdit;
  12.                LRESULT lRetVal = DefWindowProc(hWnd, uMsg, wParam, lParam);
  13.                GetClientRect( hWnd, &rectClient );       // Use client rectangle to center child.
  14.                hWndEdit = CreateWindow( "edit",                                   // class name
  15.                                         "",                                       // window name
  16.                                         WS_CHILD | WS_VISIBLE | WS_BORDER  | ES_MULTILINE |
  17.                                         ES_AUTOVSCROLL | ES_AUTOHSCROLL,          // style
  18.                                         10, 10,                                   // location
  19.                                         rectClient.right - rectClient.left - 20,  // width
  20.                                         rectClient.bottom - rectClient.top - 20,  // height
  21.                                         hWnd,                                     // parent
  22.                                         (HMENU) EDIT_ID,                          // child window ID
  23.                                         hInst,                                    // app instance
  24.                                         NULL );                                   // special parameters 
  25.               if ( hWndEdit ) 
  26.               {
  27.                  LPTSTR lpIniValuesBuffer = HeapAlloc( GetProcessHeap(),
  28.                                                        HEAP_ZERO_MEMORY,
  29.                                                        0x1000 );
  30.                  LPTSTR lpEditBuffer = HeapAlloc( GetProcessHeap(),
  31.                                                   HEAP_ZERO_MEMORY,
  32.                                                   0x1000 );
  33.                  LPTSTR lpTempInput = lpIniValuesBuffer;
  34.                  LPTSTR lpTempOutput = lpEditBuffer;
  35.  
  36.                  GetProfileSection( "Desktop",            // section name
  37.                                     lpIniValuesBuffer,    // buffer
  38.                                     0x1000 );             // buffer size
  39.  
  40.                  // Format for output to edit box. Add CR/LF after every line.
  41.                  while (*lpTempInput) 
  42.                  {
  43.                      wsprintf(lpTempOutput, "%s\r\n", lpTempInput);
  44.                      lpTempInput += (lstrlen(lpTempInput) + 1);
  45.                      lpTempOutput += lstrlen(lpTempOutput);
  46.                  }
  47.                  SendMessage( hWndEdit, WM_SETTEXT, 0,(LPARAM) lpEditBuffer );
  48.  
  49.                  HeapFree( GetProcessHeap(), 0L, lpIniValuesBuffer );
  50.                  HeapFree( GetProcessHeap(), 0L, lpEditBuffer );
  51.               }
  52.               return lRetVal;
  53.             } 
  54.  
  55.             case WM_COMMAND:       // process menu items 
  56.                  switch ( LOWORD( wParam )  )
  57.                  {
  58.                      case IDM_TEST: 
  59.                         {
  60.                            LPTSTR lpTemp;
  61.                            HWND hWndEdit = GetDlgItem( hWnd, EDIT_ID );
  62.                            if ( hWndEdit ) 
  63.                            {
  64.                               int iItem;
  65.                               LPTSTR lpIniValuesBuffer = HeapAlloc( GetProcessHeap(),
  66.                                                                     HEAP_ZERO_MEMORY,
  67.                                                                     0x1000 );
  68.                               LPTSTR lpTemp = lpIniValuesBuffer;
  69.  
  70.                               SendMessage(hWndEdit, WM_GETTEXT, 0xfff,(LPARAM) lpTemp);
  71.  
  72.                               // Format for output to section.
  73.  
  74.                               while (*lpTemp) 
  75.                               {
  76.                                  if (*lpTemp == '\r')
  77.                                     *lpTemp = ' ';
  78.                                  if (*lpTemp == '\n')
  79.                                     *lpTemp = 0; 
  80.                                  lpTemp++;
  81.                               } 
  82.  
  83.                               WriteProfileSection( "Desktop",                // section name
  84.                                                    lpIniValuesBuffer );      // buffer
  85.                               HeapFree( GetProcessHeap(), 0L, lpIniValuesBuffer );
  86.                            }
  87.                      }
  88.                      break;
  89.                   case IDM_EXIT:  // remove TestSection from WIN.INI if it exists.
  90.                               DestroyWindow( hWnd );
  91.                               break;
  92.                   }
  93.                   break;
  94.  
  95.       case WM_DESTROY: 
  96.              PostQuitMessage( 0 );
  97.       break;
  98.       default:
  99.          return DefWindowProc( hWnd, uMsg, wParam, lParam );
  100.    }
  101.    return( 0L ) ;
  102. }
  103.  
  104. #include <about.c>
  105.